﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AspDotNet.Core3.Mvc.Study.ProductDemo.Models
{
    public class ProductOperation : IProductOperation
    {
        public List<Product> GetPagingProducts(int start, int end)
        {
            return Products.Skip(start)
                .Take(end)
                .ToList();
        }

        public Product GetProductByID(int id)
        {
            return Products.Find(p => p.ID == id);
        }

        public List<Product> GetProducts()
        {
            return Products;
        }

        static List<Product> Products { get; } = new List<Product>()
        {
            new Product()
            {
                ID = 1,
                Name = "宝马",
                Date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                Price = 50000m
            },
            new Product()
            {
                ID = 2,
                Name = "法拉利",
                Date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                Price = 60000m
            },
            new Product()
            {
                ID = 3,
                Name = "保时捷",
                Date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                Price = 65000m
            },
            new Product()
            {
                ID = 4,
                Name = "一气大众",
                Date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                Price = 40000m
            }
        };
    }
}
